<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>plugins &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../index.html" />
    <link rel="next" title="tests" href="tests.html" />
    <link rel="prev" title="less" href="less.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="tests.html" title="tests"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="less.html" title="less"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="plugins">
<h1>plugins<a class="headerlink" href="#plugins" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-gozerlib.plugins">
<h2>description<a class="headerlink" href="#module-gozerlib.plugins" title="Permalink to this headline">¶</a></h2>
<p>holds all the plugins. plugins are imported modules.</p>
<dl class="class">
<dt id="gozerlib.plugins.Plugins">
<em class="property">class </em><tt class="descclassname">gozerlib.plugins.</tt><tt class="descname">Plugins</tt><a class="headerlink" href="#gozerlib.plugins.Plugins" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="(in Python v2.7)" class="reference external" href="http://docs.python.org/dev/library/functions.html#object"><tt class="xref docutils literal"><span class="pre">object</span></tt></a></p>
<p>the plugins object contains all the plugins.</p>
<dl class="method">
<dt id="gozerlib.plugins.Plugins.dispatch">
<tt class="descname">dispatch</tt><big>(</big><em>bot</em>, <em>event</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.dispatch" title="Permalink to this definition">¶</a></dt>
<dd><p>dispatch event onto the cmnds object. check for pipelines first.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>bot</em> (gozerlib.botbase,BotBase) &#8211; bot on which event took place</li>
<li><em>event</em> (gozerlib.eventbase.EventBase) &#8211; the event that triggered the command</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.plugins.Plugins.exists">
<tt class="descname">exists</tt><big>(</big><em>plugname</em><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.exists" title="Permalink to this definition">¶</a></dt>
<dd><p>see if plugin exists.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>plugname</em> (string) &#8211; name of plugin to check</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">boolean</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.plugins.Plugins.list">
<tt class="descname">list</tt><big>(</big><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.list" title="Permalink to this definition">¶</a></dt>
<dd>return list of all plugins.</dd></dl>

<dl class="method">
<dt id="gozerlib.plugins.Plugins.load">
<tt class="descname">load</tt><big>(</big><em>modname</em><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.load" title="Permalink to this definition">¶</a></dt>
<dd><p>load a plugin.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>modname</em> (string) &#8211; module name of plugin to load</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">module (the plugin)</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.plugins.Plugins.loadall">
<tt class="descname">loadall</tt><big>(</big><em>paths=</em><span class="optional">[</span><span class="optional">]</span>, <em>force=False</em><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.loadall" title="Permalink to this definition">¶</a></dt>
<dd><p>load all plugins from given paths, if force is true .. otherwise load 
all plugins for default_plugins list.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>paths</em> (list of modules) &#8211; paths of modules to search plugins in</li>
<li><em>force</em> (boolean) &#8211; whether to force loading of all found plugins</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.plugins.Plugins.needreloadcheck">
<tt class="descname">needreloadcheck</tt><big>(</big><em>bot</em>, <em>event</em>, <em>target=None</em><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.needreloadcheck" title="Permalink to this definition">¶</a></dt>
<dd><p>check if event requires a plugin to be reloaded. if so 
reload the plugin.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>bot</em> (gozerlib.botbase,BotBase) &#8211; bot on which event took place</li>
<li><em>event</em> (gozerlib.eventbase.EventBase) &#8211; the event that triggered the command</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">module (the reloaded plugin)</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.plugins.Plugins.pipelined">
<tt class="descname">pipelined</tt><big>(</big><em>bot</em>, <em>event</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.pipelined" title="Permalink to this definition">¶</a></dt>
<dd><p>split cmnds, create events for them, 
chain the queues and dispatch.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>bot</em> (gozerlib.botbase,BotBase) &#8211; bot on which event took place</li>
<li><em>event</em> (gozerlib.eventbase.EventBase) &#8211; the event that triggered the command</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.plugins.Plugins.reload">
<tt class="descname">reload</tt><big>(</big><em>modname</em><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.reload" title="Permalink to this definition">¶</a></dt>
<dd><p>reload a plugin. just load for now.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>modname</em> (string) &#8211; module name of the plugin to reload</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">module (the reloaded plugin)</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.plugins.Plugins.unload">
<tt class="descname">unload</tt><big>(</big><em>modname</em><big>)</big><a class="headerlink" href="#gozerlib.plugins.Plugins.unload" title="Permalink to this definition">¶</a></dt>
<dd><p>unload plugin .. remove related commands from cmnds object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>modname</em> (string) &#8211; module name of the plugin to remove</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">boolean</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/plugins.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; holds all the plugins. plugins are imported modules. &quot;&quot;&quot;</span>

<span class="c">## gozerlib imports</span>

<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">cmnds</span>
<span class="kn">from</span> <span class="nn">eventbase</span> <span class="kn">import</span> <span class="n">EventBase</span>
<span class="kn">from</span> <span class="nn">config</span> <span class="kn">import</span> <span class="n">Config</span>
<span class="kn">from</span> <span class="nn">persist.persist</span> <span class="kn">import</span> <span class="n">Persist</span>
<span class="kn">from</span> <span class="nn">admin</span> <span class="kn">import</span> <span class="n">plugin_packages</span><span class="p">,</span> <span class="n">default_plugins</span>

<span class="c">## basic imports</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">Queue</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">sys</span>

<span class="k">class</span> <span class="nc">Plugins</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; the plugins object contains all the plugins. &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">store</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            return plugin. </span>

<span class="sd">            :param item: plugin name to retur</span>
<span class="sd">            :type item: string</span>
<span class="sd">            :rtype: module or None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">item</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">item</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>

    <span class="k">def</span> <span class="nf">exists</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">plugname</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">            see if plugin exists.</span>

<span class="sd">            :param plugname: name of plugin to check</span>
<span class="sd">            :type plugname: string</span>
<span class="sd">            :rtype: boolean</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">plugin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">plugname</span> <span class="ow">in</span> <span class="n">name</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">True</span>

        <span class="k">return</span> <span class="bp">False</span>

    <span class="k">def</span> <span class="nf">loadall</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">paths</span><span class="o">=</span><span class="p">[],</span> <span class="n">force</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            load all plugins from given paths, if force is true .. otherwise load </span>
<span class="sd">            all plugins for default_plugins list.</span>

<span class="sd">            :param paths: paths of modules to search plugins in</span>
<span class="sd">            :type paths: list of modules</span>
<span class="sd">            :param force: whether to force loading of all found plugins</span>
<span class="sd">            :type force: boolean </span>
<span class="sd">            :rtype: None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">paths</span><span class="p">:</span>
            <span class="n">paths</span> <span class="o">=</span> <span class="n">plugin_packages</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">force</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;on demand plug loading is enabled&#39;</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">plug</span> <span class="ow">in</span> <span class="n">default_plugins</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">plug</span><span class="p">)</span>

            <span class="k">return</span>

        <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">paths</span><span class="p">:</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">plug</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>

                <span class="k">if</span> <span class="n">plug</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&quot;.py&quot;</span><span class="p">):</span>
                    <span class="n">mod</span> <span class="o">=</span> <span class="s">&quot;.&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">sep</span><span class="p">))</span>
                    <span class="n">modname</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">mod</span><span class="p">,</span> <span class="n">plug</span><span class="p">[:</span><span class="o">-</span><span class="mf">3</span><span class="p">])</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">modname</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">unload</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modname</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">            unload plugin .. remove related commands from cmnds object. </span>

<span class="sd">            :param modname: module name of the plugin to remove</span>
<span class="sd">            :type modname: string</span>
<span class="sd">            :rtype: boolean</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">cmnds</span><span class="o">.</span><span class="n">unload</span><span class="p">(</span><span class="n">modname</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">False</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">modname</span><span class="p">]</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;called </span><span class="si">%s</span><span class="s"> shutdown&#39;</span> <span class="o">%</span> <span class="n">modname</span><span class="p">)</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">AttributeError</span><span class="p">,</span> <span class="ne">KeyError</span><span class="p">):</span>
            <span class="k">pass</span>

        <span class="k">return</span> <span class="bp">True</span>

    <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modname</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">            load a plugin. </span>

<span class="sd">            :param modname: module name of plugin to load</span>
<span class="sd">            :type modname: string</span>
<span class="sd">            :rtype: module (the plugin)</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;loading </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">modname</span><span class="p">)</span>
        <span class="n">mod</span> <span class="o">=</span> <span class="nb">__import__</span><span class="p">(</span><span class="n">modname</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">modname</span><span class="p">]</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">modules</span><span class="p">[</span><span class="n">modname</span><span class="p">]</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">modname</span><span class="p">]</span><span class="o">.</span><span class="n">init</span><span class="p">()</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> init called&#39;</span> <span class="o">%</span> <span class="n">modname</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">modname</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">reload</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modname</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            reload a plugin. just load for now. </span>

<span class="sd">            :param modname: module name of the plugin to reload</span>
<span class="sd">            :type modname: string</span>
<span class="sd">            :rtype: module (the reloaded plugin)</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">unload</span><span class="p">(</span><span class="n">modname</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">modname</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">dispatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            dispatch event onto the cmnds object. check for pipelines first.</span>

<span class="sd">            :param bot: bot on which event took place</span>
<span class="sd">            :type bot: gozerlib.botbase,BotBase</span>
<span class="sd">            :param event: the event that triggered the command</span>
<span class="sd">            :type event: gozerlib.eventbase.EventBase</span>
<span class="sd">            :rtype: None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="s">&#39; | &#39;</span> <span class="ow">in</span> <span class="n">event</span><span class="o">.</span><span class="n">txt</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">pipelined</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">needreloadcheck</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">)</span>
            <span class="n">cmnds</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">pipelined</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">            split cmnds, create events for them, </span>
<span class="sd">            chain the queues and dispatch. </span>

<span class="sd">            :param bot: bot on which event took place</span>
<span class="sd">            :type bot: gozerlib.botbase,BotBase</span>
<span class="sd">            :param event: the event that triggered the command</span>
<span class="sd">            :type event: gozerlib.eventbase.EventBase</span>
<span class="sd">            :rtype: None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">origqueues</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">queues</span>
        <span class="n">event</span><span class="o">.</span><span class="n">queues</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">events</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c"># split commands</span>
        <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">event</span><span class="o">.</span><span class="n">txt</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39; | &#39;</span><span class="p">):</span>
            <span class="n">e</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
            <span class="n">e</span><span class="o">.</span><span class="n">txt</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;creating event for </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">e</span><span class="o">.</span><span class="n">txt</span><span class="p">)</span>
            <span class="n">e</span><span class="o">.</span><span class="n">bot</span> <span class="o">=</span> <span class="n">bot</span>
            <span class="n">e</span><span class="o">.</span><span class="n">makeargs</span><span class="p">()</span>
            <span class="n">events</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>

        <span class="c"># loop over events .. chain queues</span>
        <span class="n">prevq</span> <span class="o">=</span> <span class="bp">None</span>

        <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">events</span><span class="p">[:</span><span class="o">-</span><span class="mf">1</span><span class="p">]:</span>
            <span class="n">q</span> <span class="o">=</span> <span class="n">Queue</span><span class="o">.</span><span class="n">Queue</span><span class="p">()</span>
            <span class="n">e</span><span class="o">.</span><span class="n">queues</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">prevq</span><span class="p">:</span>
                <span class="n">e</span><span class="o">.</span><span class="n">inqueue</span> <span class="o">=</span> <span class="n">prevq</span>
            <span class="n">prevq</span> <span class="o">=</span> <span class="n">q</span>

        <span class="n">events</span><span class="p">[</span><span class="o">-</span><span class="mf">1</span><span class="p">]</span><span class="o">.</span><span class="n">inqueue</span> <span class="o">=</span> <span class="n">prevq</span>

        <span class="k">if</span> <span class="n">origqueues</span><span class="p">:</span>
            <span class="n">events</span><span class="p">[</span><span class="o">-</span><span class="mf">1</span><span class="p">]</span><span class="o">.</span><span class="n">queues</span> <span class="o">=</span> <span class="n">origqueues</span>

        <span class="c"># do the dispatch</span>
        <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">events</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">list</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; return list of all plugins. &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="p">[</span><span class="n">name</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">needreloadcheck</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            check if event requires a plugin to be reloaded. if so </span>
<span class="sd">            reload the plugin.</span>

<span class="sd">            :param bot: bot on which event took place</span>
<span class="sd">            :type bot: gozerlib.botbase,BotBase</span>
<span class="sd">            :param event: the event that triggered the command</span>
<span class="sd">            :type event: gozerlib.eventbase.EventBase</span>
<span class="sd">            :rtype: module (the reloaded plugin)</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">config</span> <span class="o">=</span> <span class="n">Config</span><span class="p">(</span><span class="s">&#39;mainconfig&#39;</span><span class="p">)</span>
        <span class="n">plugloaded</span> <span class="o">=</span> <span class="bp">None</span>

        <span class="k">if</span> <span class="n">config</span><span class="p">[</span><span class="s">&#39;ondemand&#39;</span><span class="p">]:</span>
            <span class="n">cmndtable</span> <span class="o">=</span> <span class="n">Persist</span><span class="p">(</span><span class="s">&#39;cmndtable&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">data</span>
            <span class="k">try</span><span class="p">:</span>

                <span class="k">if</span> <span class="n">target</span><span class="p">:</span>
                    <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;target set: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">target</span><span class="p">)</span>
                    <span class="n">cmnd</span> <span class="o">=</span> <span class="s">&#39;target-set&#39;</span>
                    <span class="n">plugin</span> <span class="o">=</span> <span class="n">target</span>

                <span class="k">else</span><span class="p">:</span>
                    <span class="kn">from</span> <span class="nn">aliases</span> <span class="kn">import</span> <span class="n">aliasget</span>
                    <span class="n">t</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">txt</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mf">0</span><span class="p">]</span>
                    <span class="n">alias</span> <span class="o">=</span> <span class="n">aliasget</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">alias</span><span class="p">:</span>
                        <span class="n">alias</span> <span class="o">=</span> <span class="n">alias</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mf">0</span><span class="p">]</span>
                    <span class="n">cmnd</span> <span class="o">=</span> <span class="n">alias</span> <span class="ow">or</span> <span class="n">t</span>
                    <span class="n">cmnd</span> <span class="o">=</span> <span class="n">cmnd</span>
                    <span class="n">plugin</span> <span class="o">=</span> <span class="n">cmndtable</span><span class="p">[</span><span class="n">cmnd</span><span class="p">]</span>

                <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;cmnd: </span><span class="si">%s</span><span class="s"> plugin: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cmnd</span><span class="p">,</span> <span class="n">plugin</span><span class="p">))</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">plugin</span><span class="p">):</span>
                    <span class="k">return</span> <span class="bp">False</span>

                <span class="n">plugloaded</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">reload</span><span class="p">(</span><span class="n">plugin</span><span class="p">)</span>

                <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;reloaded </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">plugin</span><span class="p">))</span>

            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
               <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&quot;can&#39;t find plugin to reload for </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">event</span><span class="o">.</span><span class="n">txt</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mf">0</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">plugloaded</span>

<span class="c"># the plugins object (plugs)</span>
<span class="n">plugs</span> <span class="o">=</span> <span class="n">Plugins</span><span class="p">()</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">plugins</a><ul>
<li><a class="reference external" href="#module-gozerlib.plugins">description</a></li>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="less.html"
                                  title="previous chapter">less</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="tests.html"
                                  title="next chapter">tests</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/gozerlib/plugins.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tests.html" title="tests"
             >next</a> |</li>
        <li class="right" >
          <a href="less.html" title="less"
             >previous</a> |</li>
        <li><a href="../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>